import http from "@/utils/http";

export interface ITask  {
    //taskid: number;
    test_purpose: string;
    expected_result: string;
    //test_status: string;
    test_environment: string;
    task_creator: string;
    create_time: Date;
    //finish_time: Date;
    svn: string;
    test_data: string;
    //test_name: string;
    remark: string;
    product_name: string;
    test_infer: string;
    modelnames: string[];
    file: string;
}

export class TaskService {
    static async createTask(task: ITask) {
        return http.post({
            url: 'test/create',
            data: task
        })
    }

    static async getAllTasks() {
        return http.post({
            url: 'test/select'
        })
    };

    static async getTasksByStatus(test_status: string) {
        return http.post({
            url: 'test/status_select',
            data: {
                test_status: test_status
            }
        })
    };

    static async getHistoryTasks() {
        return http.post({
            url: 'test/history_select',
        })
    };

    static async getAwaitTasks() {
        return http.post({
            url: 'test/await_select',
        });
    }

    static async updateTaskStatus(taskid : number, test_status : string) {
        return http.put({
            url: 'test/update',
            data: {
                taskid: taskid,
                test_status: test_status
            }
        });
    }

    static async updateTaskFinishTime(taskid : number, finish_time : Date) {
        return http.put({
            url: 'test/update',
            data: {
                taskid: taskid,
                finish_time: finish_time
            }
        });
    }

    static async deleteTask(taskid : number) {
        return http.delete({
            url: 'test/delete',
            data: {
                taskid: taskid
            }
        });
    }

    static async startTask(create_time : string, serverIp : string, test_params : string) {
        return http.post({
            url: 'test/addtask',
            data: {
                filename: create_time,
                url: serverIp,
                params: test_params 
            }
        })
    }

    static async getQueue(serverIp : string){
        return http.post({
            url: 'test/getqueue',
            data: {
                url: serverIp
            }
        })
    }

    static async getRunning(serverIp : string){
        return http.post({
            url: 'test/getrunning',
            data: {
                url: serverIp
            }
        })
    }

    static async killTask(){
        return http.post({
            url: 'test/killtask',
        });
    }
}